﻿using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Serialization;
using SpectrumAnalyser.Common.Logs.Attributes;
using SpectrumAnalyser.Config.Contract;
using System.ServiceModel;
using SpectrumAnalyser.Config.Service.Config;

namespace SpectrumAnalyser.Config.Service
{
    [Log]
    [ServiceBehavior(IncludeExceptionDetailInFaults = true, InstanceContextMode = InstanceContextMode.Single)]
    public class ConfigServiceController : IConfigService
    {
        private const string CONFIGURATION_PATH = "Config/config.xml";

        [Foo]
        public void Ping()
        {
            
        }

        public IList<ModelObjects.Instance> GetInstances()
        {
            var configuration = new Configuration(CONFIGURATION_PATH);

            IList<ModelObjects.Instance> result = configuration.Instances.Select(x => new ModelObjects.Instance
                                                                                          {
                                                                                              ConnectionString = 
                                                                                                  x.ConnectionString,
                                                                                              Name = x.Name,
                                                                                              InstanceType = x.InstanceType
                                                                                          }).ToList();

            return result;
        }

        public ModelObjects.Instance GetInstanceByName(string instanceName)
        {
            throw new System.NotImplementedException();
        }
    }
}